package train;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class Train {

	private final int MAX_TRAIN_PLACES = 50;

	private String itinerary;
	private Double ticketPrize;
	private List<Boolean> trainSits;
	private Boolean isTrackCanceld;
	
	public Train(){
		this.trainSits = new ArrayList<>();
	}
	
	/**
	 * @return the isTrackCanceld
	 */
	public Boolean getIsTrackCanceld() {
		return isTrackCanceld;
	}

	/**
	 * @param cancelTrac sets isTrackCanceld to true
	 */
	public void cancelTrac() {
		this.isTrackCanceld = true;
	}
	
	public void bookAll(){
		this.trainSits = new ArrayList<>(MAX_TRAIN_PLACES);
		for (int i = this.trainSits.size(); i < MAX_TRAIN_PLACES; i++){
			this.trainSits.add(true);
		}
	}
	
	public void bookTicket() throws ArrayIndexOutOfBoundsException, ArrayStoreException{
		
		if (this.isTrackCanceld){
			throw new ArrayStoreException("this.trainSits.size() == " + (MAX_TRAIN_PLACES - 1));
		}
		else if(this.trainSits.size() >= (MAX_TRAIN_PLACES - 1)){
			throw new ArrayIndexOutOfBoundsException("this.trainSits.size() > " + (MAX_TRAIN_PLACES - 1));
		}else{
			this.trainSits.add(true);
		}
		
	}
	
	public String getTrackSchedule(String sc){
		Schedule scTemp = Schedule.valueOf(sc.toUpperCase());
		return scTemp.getTime();
	}

	/**
	 * @return the itinerary
	 */
	public String getItinerary() {
		return itinerary;
	}

	/**
	 * @param itinerary
	 *            the itinerary to set
	 */
	public void setItinerary(String itinerary) {
		this.itinerary = itinerary;
	}

	/**
	 * @return the ticketPrize
	 */
	public Double getTicketPrize() {
		return ticketPrize;
	}

	/**
	 * @param ticketPrize
	 *            the ticketPrize to set
	 */
	public void setTicketPrize(Double ticketPrize) {
		this.ticketPrize = ticketPrize;
	}

	/**
	 * @return the trainSits
	 */
	public List<Boolean> getTrainSits() {
		return trainSits;
	}
}
